package com.day05;

import java.util.Arrays;

/**
 * java.util.Arrays类即为操作数组的工具类，包含了用来操作数组(比如排序和搜索)的各种方法
 *
 * @author 薛虎
 */
public class ArraysUtils {

    public static void main(String[] args) {
        //1.boolean equals比较两个数组是否相等
        int[] arr1 = new int[]{1, 2, 3, 4};
        int[] arr2 = new int[]{1, 3, 2, 4};

        boolean isEquals = Arrays.equals(arr1, arr2);

        System.out.println(isEquals);

        //toString 输出数组信息
        System.out.println(Arrays.toString(arr1));

        //fill将指定的值填充到数组当中,全部替换
        Arrays.fill(arr1, 12);
        System.out.println(Arrays.toString(arr1));


        //sort 排序
        Arrays.sort(arr2);
        System.out.println(Arrays.toString(arr2));

        //二分查找 int binarySearch,获取指定元素的索引
        int[] arr3 = new int[]{-98, -34, 2, 34, 54, 66, 79, 106};
        int binarySearch = Arrays.binarySearch(arr3, 106);
        if (0 <= binarySearch) {
            System.out.println(binarySearch);
        } else {
            System.out.println("未找到");
        }


    }
}
